package com.joysuch.wwyt.bp.enums;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author ZhaoQiuWei
 * @Date 2022/6/8 16:14
 */
public enum ApiAlarmTypeEnum {
    AI(0, "ai", "AI报警"),
    AREA_ALARM(1, "areaAlarm", "人员在岗在位报警"),
    JOBA_LARM_EVENT(2, "jobAlarmEvent", "作业票报警"),
    ALARM_EVENT(3, "alarmEvent", "车辆报警");

    private Integer id;
    private String code;
    private String name;

    public Integer getId() {
        return id;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setName(String name) {
        this.name = name;
    }

    ApiAlarmTypeEnum(Integer id, String code, String name) {
        this.id = id;
        this.code = code;
        this.name = name;
    }

    private static final Map<String, ApiAlarmTypeEnum> lookup = new HashMap<>();
    private static final Map<Integer, ApiAlarmTypeEnum> idMap = new HashMap<>();
    private static final Map<String, ApiAlarmTypeEnum> nameMap = new HashMap<>();

    static {
        for (ApiAlarmTypeEnum e : EnumSet.allOf(ApiAlarmTypeEnum.class)) {
            lookup.put(e.code, e);
            idMap.put(e.getId(), e);
            nameMap.put(e.name,e);
        }
    }

    public static Integer getIdByCode(String code) {
        ApiAlarmTypeEnum e = lookup.get(code);
        if (e != null) {
            return e.id;
        }
        return null;
    }

    public static Integer getIdByName(String name) {
        ApiAlarmTypeEnum e = nameMap.get(name);
        if (e != null) {
            return e.id;
        }
        return null;
    }

    public static String getNameById(Integer id) {
        ApiAlarmTypeEnum e = idMap.get(id);
        if (e != null) {
            return e.name;
        }
        return null;
    }

}
